package cn.da.shuai.mq.rabbitmq.producer;

import cn.da.shuai.mq.rabbitmq.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessage(Object message) {
        rabbitTemplate.convertAndSend(
            RabbitMQConfig.DEFAULT_EXCHANGE,
            RabbitMQConfig.DEFAULT_ROUTING_KEY,
            message
        );
    }

    public void sendMessage(String exchange, String routingKey, Object message) {
        rabbitTemplate.convertAndSend(exchange, routingKey, message);
    }
}